﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="fhdb" content="true">
    <title>实名认证</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/authentication.css">
    <script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="css/bootstrapValidator.css"/>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrapValidator.js"></script>
    <script src="js/jquery.form.min.js" type="text/javascript"></script>
</head>
<body>
    <div class="phoneError">
    </div>
    <div class="backBox" onClick="javascript:history.back(-1);">
        <span class="glyphicon glyphicon-chevron-left"></span>
    </div>
    <div class="topTitle ">实名认证</div>
    <form id="defaultForm">
        <div class="bigBox regBigBox">
            <div class="passBox form-group">
                <span class="">姓名：</span><input type="text" name="TB_USERNAME" placeholder="请输入您的真实姓名"/>
            </div>
            <div class="passBox form-group">
                <span class="">身份证：</span><input type="text" name="TB_IDCARD" placeholder="请输入您的身份证号码"/>
            </div>
            <div class="form-group form-group">
                <button type="submit" class="btn btnBox" id="btnBox">提交</button>
            </div>
        </div>
    </form> 
</body>
<script>
    $(document).ready(function () {
        $.ajax({
            type: "post",
            url: "../../BaseRefWeb.aspx?stype=ISpMemberFun&method=GetIDCard&type=sp",
            success: function (result) {
                var data = JSON.parse(result);
                if (data.TB_CARD_STATE != false) {
                    $("input[name='TB_USERNAME']").val(data.TB_USERNAME)
                    $("input[name='TB_IDCARD']").val(data.TB_IDCARD)
                    $("input[name='TB_USERNAME']").attr("readonly", "true");
                    $("input[name='TB_IDCARD").attr("readonly", "true");
                    $("#btnBox").hide();
                }
            }
        });
        $('#defaultForm').bootstrapValidator({
            fields: {
                TB_USERNAME: {
                    validators: {
                        notEmpty: {
                            message: '姓名不能为空'
                        }
                    }
                },
                TB_IDCARD: {
                    validators: {
                        notEmpty: {
                            message: '身份证号码不能为空！'
                        },
                        regexp: {
                            regexp: /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/,
                            message: '身份证号码格式不正确，为15位和18位身份证号码！'
                        }
                    }
                }
            }
        })
    })
    //提交表单数据
    $('#btnBox').click(function (event) {
        /* Act on the event */
        /*手动验证表单，当是普通按钮时。*/
        $('#defaultForm').data('bootstrapValidator').validate(); //启用验证
        var flag = $('#defaultForm').data('bootstrapValidator').isValid()//验证是否通过true/false
        if (flag) {
            $("#defaultForm").ajaxSubmit({
                type: "post",
                url: "../../BaseRefWeb.aspx?stype=ISpMemberFun&method=DoIdCardSave&type=sp",
                dataType: "json",
                success: function (result) {
                    console.log(result);
                    if (result.success == false) {
                        $('.phoneError').text(result.msg);
                        var top = ($(window).height() - $('.phoneError').height()) / 2;
                        var left = ($(window).width() - $('.phoneError').width()) / 2;
                        var scrollTop = $(document).scrollTop();
                        var scrollLeft = $(document).scrollLeft();
                        $('.phoneError').css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
                        setTimeout(function () {
                            $('.phoneError').hide();
                        }, 1000)
                    }
                    else {
                        $('.phoneError').text(result.msg);
                        var top = ($(window).height() - $('.phoneError').height()) / 2;
                        var left = ($(window).width() - $('.phoneError').width()) / 2;
                        var scrollTop = $(document).scrollTop();
                        var scrollLeft = $(document).scrollLeft();
                        $('.phoneError').css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
                        setTimeout(function () {
                            $('.phoneError').hide();
                            window.location.reload();
                        }, 1000)
                    }
                }
            });
        }
    });
</script>
</html>